Home:ALL Converter>Rstudio Plot multi lines

Rstudio Plot multi lines

Ask Time:2020-02-24T01:15:26         Author:user3203275

Json Formatter

I want to plot many different lines in one plot. I wrote the following code, but it creates new plots as new lines are added. How could I get only one final plot?

plot(Rp_cum_optimal,type="l",lwd=5, ylim=c(-1,max4plot)) #optimum solution plot
lines(cumsum(asset_returns[,2]),col="red") #S&P500 plot
lines(cumsum(asset_returns[,3]),col="red") #S&P500 plot
lines(cumsum(asset_returns[,4]),col="red") #S&P500 plot
lines(cumsum(asset_returns[,5]),col="red") #S&P500 plot
lines(cumsum(asset_returns[,6]),col="red") #S&P500 plot
lines(cumsum(asset_returns[,7]),col="red") #S&P500 plot
lines(cumsum(asset_returns[,8]),col="red") #S&P500 plot
lines(cumsum(asset_returns[,9]),col="red") #S&P500 plot
lines(cumsum(asset_returns[,10]),col="red") #S&P500 plot

Author:user3203275,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364770/rstudio-plot-multi-lines
yy